package net.wanho.controller;


import net.wanho.po.Goods;
import net.wanho.service.GoodsService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.wanho.vo.AjaxResult;
import org.springframework.web.bind.annotation.*;
import java.io.Serializable;
import lombok.RequiredArgsConstructor;



import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author 汤小洋
 * @since 2025-09-25
 */
@Api(tags = "商品表接口")
@RestController
@RequestMapping("/goods")
@RequiredArgsConstructor
public class GoodsController {

    private final GoodsService goodsService;

    @ApiOperation("商品表分页查询")
    @GetMapping("/list")
    public AjaxResult findPage(@ApiParam("页码") @RequestParam(defaultValue = "1") int pageNum,
                              @ApiParam("页大小") @RequestParam(defaultValue = "5") int pageSize,
                              @ApiParam("查询条件") Goods goods){
        PageInfo<Goods> pageInfo = goodsService.findPage(pageNum,pageSize,goods);
        return AjaxResult.success(pageInfo);
    }

    @ApiOperation("根据主键查询商品表")
    @GetMapping("/{goodsId}")
    public AjaxResult findById(@PathVariable Serializable goodsId){
        return AjaxResult.success(goodsService.findById(goodsId));
    }

    @ApiOperation("新增商品表")
    @PostMapping
    public AjaxResult add(@RequestBody Goods goods){

        goodsService.add(goods);
        return AjaxResult.success();
    }

    @ApiOperation("修改商品表")
    @PutMapping
    public AjaxResult modify(@RequestBody Goods goods){
        goodsService.modify(goods);
        return AjaxResult.success();
    }

    @ApiOperation("根据主键删除商品表")
    @DeleteMapping("/{goodsId}")
    public AjaxResult removeById(@PathVariable Serializable goodsId){
        goodsService.removeById(goodsId);
        return AjaxResult.success();
    }

}
